package com.connector.base.message.model;

import com.alibaba.fastjson.JSONObject;
import com.connector.base.connection.Connection;
import com.connector.base.protocol.Packet;

public final class OkMessage extends JsonBodyMessage
{
    public String type;
    public String data;
    
    public OkMessage setType(final String type) {
        this.type = type;
        return this;
    }
    
    public OkMessage setData(final String data) {
        this.type = "0";
        this.data = data;
        return this;
    }
    
    public OkMessage(final Packet packet, final Connection connection) {
        super(packet, connection);
    }
    
    @Override
    public void jsonToFields(final JSONObject jsonBody) {
        this.type = (jsonBody.containsKey((Object)"type") ? jsonBody.getString("type") : null);
        this.data = (jsonBody.containsKey((Object)"data") ? jsonBody.getString("data") : null);
    }
    
    @Override
    public JSONObject fieldToJson() {
        final JSONObject resultObj = new JSONObject();
        resultObj.put("type", (Object)this.type);
        resultObj.put("data", (Object)this.data);
        return resultObj;
    }
    
    public OkMessage buildResult(final String data) {
        final JSONObject dataObj = new JSONObject();
        dataObj.put("success", (Object)true);
        dataObj.put("msg", (Object)data);
        return this.setData(dataObj.toJSONString());
    }
    
    public String getType() {
        return this.type;
    }
    
    public String getData() {
        return this.data;
    }
    
    @Override
    public String toString() {
        return "OkMessage(type=" + this.getType() + ", data=" + this.getData() + ")";
    }
    
    public OkMessage() {
    }
}
